home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 09, No. 06 (1988-06)(MicroSPARC)(Side A).zip / Nibble Volume 09, No. 06 (1988-06)(MicroSPARC)(Side A).po / APM.S < prev    next >
Text File  |  1996-12-24  |  8KB  |  197 lines

  1. ***************************
  2. * APPLESOFT PROGRAM MOVER *
  3. *     BY  MIKE MIYAKE     *
  4. ***************************
  5. PAGE          EQU 6               holds dest. page #
  6. TEMP          EQU 7               holds source page - dest.page
  7. LINK          EQU 8               holds link field addresses
  8. A1              EQU $3C             source block start ptr.for move
  9. A2              EQU $3E             source end ptr.for move
  10.  
  11. A4              EQU $42             dest.ptr for move
  12. TXTTAB      EQU $67             start of BASIC program ptr.
  13. VARTAB      EQU $69             start of variables ptr.
  14. ARYTAB      EQU $6B             start of array space ptr.
  15. STREND      EQU $6D             end of array storage ptr.
  16. FRETOP      EQU $6F             bottom of strings ptr.
  17. VARPNT      EQU $83             general storage
  18. PGREND      EQU $AF             end of program ptr.
  19. TXTPTR      EQU $B8             address being interpreted
  20. PTR            EQU $CE
  21. MOVE          EQU $FE2C           monitor move routine
  22.                          ;----------------------------
  23.                   ORG $8E00
  24.                          ;----------------------------
  25.                   LDA PAGE            get page #
  26.                   STA A4+1            insert in dest.
  27.                   CMP #8              is dest.page too low?
  28.                   BCC BADPAGE         yes, then exit
  29.                   SBC TXTTAB+1        find difference
  30.                   STA TEMP            save it
  31.                   CLC
  32.                   ADC STREND+1
  33.                   CMP FRETOP+1        is dest.page too high?
  34.                   BCC GOOD            no, then branch & begin
  35. BADPAGE    RTS
  36. GOOD          LDY #0              set MOVE parms
  37.                   STY A1
  38.                   STY A4
  39.                   INY
  40.                   STY LINK            set link field ptrs
  41.                   LDA TXTTAB+1
  42.                   STA A1+1
  43.                   STA LINK+1
  44.                   LDA STREND          copy STREND for MOVE
  45.                   STA A2
  46.                   LDA STREND+1
  47.                   STA A2+1
  48.                   LDA VARTAB
  49.                   STA PTR             copy VARTAB
  50.                   LDY VARTAB+1
  51.                   STY PTR+1
  52. L1              CMP ARYTAB          end of simple variables?
  53.                   LDA PTR+1
  54.                   SBC ARYTAB+1
  55.                   BCS L5              yes, branch to do arrays
  56.                   LDY #0
  57.                   LDA (PTR),Y         fetch 1st byte of var.name
  58.                   BMI L2              if neg, it may be a FN
  59.                   INY                 if pos, fetch next byte--
  60.                   LDA (PTR),Y         must be neg.to be string
  61.                   BPL L4              if pos, branch to get next var
  62.                   LDY #4
  63.                   BPL L3
  64. L2              INY                 (FN's)
  65.                   LDA (PTR),Y         2nd byte of FN must be pos
  66.                   BMI L4              else branch to get next var.
  67.                   LDY #3
  68.                   CLC
  69.                   LDA (PTR),Y         adjust FN argument ptr.
  70.                   ADC TEMP
  71.                   STA (PTR),Y
  72.                   LDY #5
  73. L3              LDA (PTR),Y         get FN formula/string ptr
  74.                   CMP FRETOP+1        is it a string literal or FN?
  75.                   BCS L4              no, then get next variable
  76.                   ADC TEMP            adjust ptr.to FN/string
  77.                   STA (PTR),Y
  78. L4              CLC                 get ptr.to next variable
  79.                   LDA PTR
  80.                   ADC #7              simple vars.stored in 7 bytes
  81.                   STA PTR
  82.                   BCC L1
  83.                   INC PTR+1
  84.                   BCS L1              always branch
  85. L5              LDA PTR             begin to process arrays
  86.                   CMP STREND          has end of arrays been reached?
  87.                   LDA PTR+1
  88.                   SBC STREND+1
  89.                   BCS L12             yes, branch to do BASIC ptrs
  90.                   LDY #2              no, get offset to next array
  91.                   CLC
  92.                   LDA PTR
  93.                   STA VARPNT          save ptr.to current array
  94.                   ADC (PTR),Y         add offset to next array
  95.                   PHA
  96.                   INY
  97.                   LDA PTR+1
  98.                   STA VARPNT+1
  99.                   ADC (PTR),Y
  100.                   STA PTR+1           and save ptr.to next array
  101.                   PLA
  102.                   STA PTR
  103.                   LDY #0
  104.                   LDA (VARPNT),Y      fetch 1st byte in var.name
  105.                   BMI L5              if neg, it's not a string--branch
  106.                   INY
  107.                   LDA (VARPNT),Y      fetch 2nd byte
  108.                   BPL L5              if pos, it's not a string--branch
  109.                   LDY #4              (check string arrays only)
  110.                   LDA (VARPNT),Y      fetch # of indices
  111.                   ASL                 2 bytes/index
  112.                   BCC L6
  113.                   INC VARPNT+1        find zeroth element:
  114.                   CLC
  115. L6              ADC VARPNT          add header location to
  116.                   BCC L7              2 * the # of indices
  117.                   INC VARPNT+1
  118.                   CLC
  119. L7              ADC #5              plus 5 bytes overhead
  120.                   STA VARPNT          save in VARPNT
  121.                   BCC L8
  122.                   INC VARPNT+1
  123. L8              LDY #2              get MSB of ptr
  124. L9              LDA (VARPNT),Y
  125.                   CMP FRETOP+1        is string a literal?
  126.                   BCS L10             no, get next element
  127.                   ADC TEMP            yes, adjust ptrs
  128.                   STA (VARPNT),Y
  129. L10            CLC                 fetch next element
  130.                   LDA VARPNT
  131.                   ADC #3              3 bytes each
  132.                   STA VARPNT
  133.                   BCC L11
  134.                   INC VARPNT+1
  135. L11            CMP PTR             all elements done?
  136.                   LDA VARPNT+1
  137.                   SBC PTR+1
  138.                   BCC L9              no, get another
  139.                   BCS L5              yes, get next array
  140. L12            LDX #8
  141. L13            DEX
  142.                   CLC
  143.                   LDA TXTTAB,X        reset BASIC pointers:
  144.                   ADC TEMP            TXTTAB, VARTAB,ARYTAB,
  145.                   STA TXTTAB,X        STREND
  146.                   DEX
  147.                   BNE L13
  148.                   CLC
  149.                   LDA PGREND+1        adjust end of program ptr
  150.                   ADC TEMP
  151.                   STA PGREND+1
  152.                   LDA TXTPTR+1        adjust text pointer
  153.                   CMP #2              but only if program is running
  154.                   BEQ L14
  155.                   CLC
  156.                   ADC TEMP
  157.                   STA TXTPTR+1
  158. L14            LDY #0
  159.                   LDA (LINK),Y        reset link field addresses
  160.                   TAX                 fetch & save ptr to next addr
  161.                   INY
  162.                   LDA (LINK),Y        get MSB of addr
  163.                   BEQ L15             if it's a zero, branch--we're done
  164.                   PHA                 save it
  165.                   CLC
  166.                   ADC TEMP            adjust it
  167.                   STA (LINK),Y        put it back in the program
  168.                   STX LINK            install ptrs. saved earlier
  169.                   PLA
  170.                   STA LINK+1
  171.                   BNE L14             branch always
  172. L15            DEY
  173.                   LDA PAGE
  174.                   CMP A1+1            is move up or down?
  175.                   BCS L16             if up, branch
  176.                   JMP MOVE            else use monitor MOVE & exit
  177. L16            LDA STREND+1        set dest. ptrs
  178.                   STA A4+1
  179.                   LDA STREND
  180.                   STA A4
  181. L17            LDA (A2),Y          fetch a byte off the top
  182.                   STA (A4),Y          move it
  183.                   SEC
  184.                   LDA A2              adjust pointers
  185.                   SBC #1
  186.                   STA A4
  187.                   STA A2
  188.                   BCS L18
  189.                   DEC A4+1
  190.                   DEC A2+1
  191. L18            CMP A1              are we done?
  192.                   LDA A2+1
  193.                   SBC A1+1
  194.                   BCS L17             if carry set, go back & repeat
  195.                   RTS                 if carry clear, we're done
  196.  
  197.